import re
import os
from common.my_conf import My_Conf
from common.my_path import CONF_PATH



class My_Replace_data:
    '''
    临时变量类
    '''
    member_id = ''
    token_data = ''
    phone = ''
    loan_id=''



#匹配替换配置文件中的数据
def replace_data(data):
    conf = My_Conf(os.path.join(CONF_PATH, 'conf.ini'))

    #正则规则
    r = r'#(.+?)#'

    #判断匹配是否成功
    while re.search(r,data):
        res = re.search(r,data)

        #用来匹配要替换的值
        itme = res.group()

        #要替换的值
        key = res.group(1)
        try:
            data = data.replace(itme,conf.get_str('login',key))
        except:
            data = data.replace(itme, getattr(My_Replace_data,key))

    return data







if __name__ == '__main__':
    data = '{"user":"#mobile_phone#","password":"#password#"}'


    res = my_replace.replace_data(data)
    print(res)